package persistencia;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class ConfigDAO {
    private static String URL;
    private static String DRIVER;
    
    public java.sql.Connection getConnection() {
        try {
           Connection con = java.sql.DriverManager.getConnection(URL, "Examen12", "Examen12");
           return con;
         } catch( java.sql.SQLException e ) { 
           System.out.println(e.getMessage());	 
           return null;
        }
    }
    
    public PreparedStatement GetPreparedStatement(String sql)
    {
		Connection con = getConnection();
		PreparedStatement pstmt = null;
		try {
			pstmt = con.prepareStatement(sql);
     	} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return pstmt;
    }
    
    public static void setConnection(){
		ConfigDAO.setConnectionString();
		ConfigDAO.loadDriverOdbc();
    }
    
    public static void loadDriverOdbc() {
        try {
            Class.forName(DRIVER).newInstance();
        } catch( ClassNotFoundException e ) { 
        	System.out.println(e.getMessage());
        } catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
    }
     
    public static void setConnectionString() {
    	DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
    	URL = "jdbc:odbc:parcial";
    }

}
